/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.example;

import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.swirrel.annotation.ActionPerformed;
import org.swirrel.component.SwFrame;

/**
 *
 * @author Gronau
 */
public class ThreadedCallExampleSwFrame extends SwFrame {

    @ActionPerformed("call")
    private final JButton edtButton = new JButton("I block!");
    @ActionPerformed(value = "call", threaded = true)
    private final JButton threadedButton = new JButton("I don't!");
    private JLabel label = new JLabel("idle");

    public ThreadedCallExampleSwFrame() {
        super("Swirrel Threaded Call Example");
        setSize(500, 500);
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        panel.add(edtButton);
        panel.add(threadedButton);
        panel.add(label);
        getContentPane().add(panel);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void call() {
        label.setText("working...");
        long time = System.currentTimeMillis();
        while (System.currentTimeMillis() < time + 10000) {
            try {
                Thread.sleep(20);
            } catch (InterruptedException ex) {
                //don't care
            }
        }
        label.setText("idle");
    }

    public static void main(String[] args) {
        new ThreadedCallExampleSwFrame();
    }
}
